﻿using System;

namespace YaAppoint.OnlineServiceCache
{
    public class OnlineServieCacheItem<T>
    {
        // 值
        public T Value { get; set; }

        // 创建时间
        public DateTime CreatedTime { get; set; }

        // 过期时间(TimeSpan)
        public TimeSpan? Expiration { get; set; }

        // 过期时间(DateTime)
        public DateTime AbsoluteExpiration => Expiration.HasValue ? CreatedTime.Add(Expiration.Value) : DateTime.MaxValue;

        public bool IsExpired => DateTime.Now > AbsoluteExpiration;

        public OnlineServieCacheItem(T value, TimeSpan? expiration = null)
        {
            Value = value;
            CreatedTime = DateTime.Now;
            Expiration = expiration;
        }
    }
}
